/**
 *Project: jh-framework
 *File: cn.xkshow.framework.webservice.client.PPMeetClient.java 
 *Author: admin@xkshow.cn with the copyrite
 ****************************************************************
 *   VERSION       DATE            BY       CHANGE/COMMENT
 * --------------------------------------------------------------
 *    1.0        2013-4-11        xkshow.cn         create
 ****************************************************************
 *note:
 ***************************************************************/ 
package cn.xkshow.framework.webservice.client;

import net.sf.json.JSONObject;

import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import cn.xkshow.commons.http.HttpClientHandle;

public class PPMeetClient {
	private static Log logger = LogFactory.getLog(PPMeetClient.class);
	private final String url = "http://dfz.ppmeet.net/";
	private final String code = "V29Vb152ACldPgltU2UGeFIgXCRTKgFtBGdTaAFzAn5VawQ0CCdcJw41VCxWdgA5XTE";
	private static PPMeetClient instance = null;
	private PPMeetClient(){};
	
	public static PPMeetClient getInstance(){
		if(null == instance){
			instance = new PPMeetClient();
		}
		return instance;
	}
	
	/**
	 * addMeet
	 * @param: 
	 * @return: mid
	 */
	public String addmeet(String u){
		String ret = "0";
		try {
			NameValuePair[] data = {
					new NameValuePair("r", "/api/addMeet"),
					new NameValuePair("u", u),
					new NameValuePair("type", "2"),
					new NameValuePair("videosize", "300"),
					new NameValuePair("smallvideo", "1,1")};
			JSONObject jobj = HttpClientHandle.getInstance().getJsonObjectByResult("POST", this.url, data);
			String mid = jobj.getString("mid");
			ret = mid = mid.substring(mid.indexOf("mid=")+4);
		} catch (Exception e) {
			// TODO: handle exception
			ret = "error";
		}finally{
			return ret;
		}
	}
	
	/**
	 * joinmeet
	 * @param: 
	 * @return: meeturl
	 */
	public String joinmeet(String compere, String nickname){
		String meeturl = "0";
		try {
			NameValuePair[] data = {
					new NameValuePair("r", "/api/joinmeet"),
					new NameValuePair("founder", compere),
					new NameValuePair("u", nickname),
					new NameValuePair("type", "guest")};
			JSONObject jobj = HttpClientHandle.getInstance().getJsonObjectByResult("POST", this.url, data);
			meeturl = jobj.getString("url");
		} catch (Exception e) {
			// TODO: handle exception
			meeturl = "error";
		}finally{
			return meeturl;
		}
	}
	
	public static void main(String[] args) {
		System.out.println(PPMeetClient.getInstance().addmeet("admin@xkshow.cn"));
//		System.out.println(PPMeetClient.getInstance().joinmeet("admin@xkshow.cn","guest"));
	}
}
